package com.wlcb.jpower.chat.controller.push;

import com.alibaba.fastjson.JSONObject;
import com.wlcb.jpower.chat.reply.ReplyEntity;
import com.wlcb.jpower.chat.service.BaiduUnitService;
import com.wlcb.jpower.module.base.enums.JpowerError;
import com.wlcb.jpower.module.base.exception.JpowerAssert;
import com.wlcb.jpower.module.base.vo.ResponseData;
import com.wlcb.jpower.module.common.controller.BaseController;
import com.wlcb.jpower.module.common.utils.ReturnJsonUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;
import java.util.Map;

/**
 * @author: fei
 * @version: v1.0
 * @time: 2021/4/15 17:14
 * @desc: 这个接口没啥用，可能会有用，目前用来测试百度unit功能
 */
@ApiIgnore
@RestController
@RequestMapping("unit")
@RequiredArgsConstructor
public class UnitController extends BaseController {

    private final BaiduUnitService unitService;

    @PostMapping("query")
    public ResponseData<List<ReplyEntity.ReplyBody>> query(@RequestBody Map<String, String> map) {

        JpowerAssert.notEmpty(map.get("query"), JpowerError.Arg,"query不可为空");
        JpowerAssert.notEmpty(map.get("userId"), JpowerError.Arg,"userId不可为空");

        String say = unitService.say(map.get("query"), map.get("userId"));
        List<ReplyEntity.ReplyBody> replyBodies = JSONObject.parseArray(say, ReplyEntity.ReplyBody.class);
        return ReturnJsonUtil.ok("操作成功", replyBodies);
    }
}
